package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.system.domain.dto.ScenicSpotsDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.ScenicSpots;
import com.ruoyi.system.service.IScenicSpotsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 景点信息Controller
 * 
 * @author ruoyi
 * @date 2025-05-18
 */
@RestController
@RequestMapping("/system/spots")
public class ScenicSpotsController extends BaseController
{
    @Autowired
    private IScenicSpotsService scenicSpotsService;

    /**
     * 查询景点信息列表
     */
    @GetMapping("/list")
    public TableDataInfo list(ScenicSpots scenicSpots)
    {
        startPage();
        List<ScenicSpotsDto> list = scenicSpotsService.selectScenicSpotsList(scenicSpots);
        return getDataTable(list);
    }

    @PostMapping("/deleteSpotsAndStore/{spotId}/{storeId}")
    public AjaxResult deleteSpotsAndStore(@PathVariable("spotId") Long spotId, @PathVariable("storeId") Long storeId)
    {
        return toAjax(scenicSpotsService.deleteSpotsAndStore(spotId,storeId));
    }

    @PostMapping("/addSpotsAndStore/{spotId}/{storeId}")
    public AjaxResult addSpotsAndStore(@PathVariable("spotId") Long spotId, @PathVariable("storeId") Long storeId)
    {
        return toAjax(scenicSpotsService.addSpotsAndStore(spotId,storeId));
    }

    /**
     * 导出景点信息列表
     */
    @Log(title = "景点信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ScenicSpots scenicSpots)
    {
        List<ScenicSpotsDto> list = scenicSpotsService.selectScenicSpotsList(scenicSpots);
        ExcelUtil<ScenicSpotsDto> util = new ExcelUtil<ScenicSpotsDto>(ScenicSpotsDto.class);
        util.exportExcel(response, list, "景点信息数据");
    }

    /**
     * 获取景点信息详细信息
     */
    @GetMapping(value = "/{spotId}")
    public AjaxResult getInfo(@PathVariable("spotId") Integer spotId)
    {
        return success(scenicSpotsService.selectScenicSpotsBySpotId(spotId));
    }

    /**
     * 新增景点信息
     */
    @Log(title = "景点信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ScenicSpots scenicSpots)
    {
        return toAjax(scenicSpotsService.insertScenicSpots(scenicSpots));
    }

    /**
     * 修改景点信息
     */
    @Log(title = "景点信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ScenicSpots scenicSpots)
    {
        return toAjax(scenicSpotsService.updateScenicSpots(scenicSpots));
    }

    /**
     * 删除景点信息
     */
    @Log(title = "景点信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{spotIds}")
    public AjaxResult remove(@PathVariable Integer[] spotIds)
    {
        return toAjax(scenicSpotsService.deleteScenicSpotsBySpotIds(spotIds));
    }
}
